using DimensionsHelper.Common.Utils;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public abstract class AnalysisSignatureWithParameter : AnalysisDeclaration
{
    private readonly List<AnalysisParameterSignature> _parameters = [];

    protected AnalysisSignatureWithParameter(AnalysisBoundKinds boundKind,
        SignatureWithParameters syntaxNode,
        AnalysisNode? parent) : base(boundKind, syntaxNode, parent)
    {
        Syntax = syntaxNode;
        syntaxNode.Parameters.ForEach(p =>
        {
            AnalysisParameterSignature parameter = AnalysisNodeFactory.ParameterSignature(p, this);
            _parameters.Add(parameter);
        });
        Binding = AnalysisNodeFactory.TypeBinding(syntaxNode.Binding, this);
    }

    public override SignatureWithParameters Syntax { get; }

    public AnalysisTypeBinding Binding { get; }

    public override int ChildrenCount => _parameters.Count + 2;

    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return [NameIdentifier, .._parameters, Binding];
    }

    internal override void AddChild(AnalysisNode child)
    {
        throw new NotSupportedException("AnalysisSignatureWithParameter is read-only.");
    }
}